package main

import (
	"fmt"
	"time"
)

func main() {
	p := fmt.Println
	//得到当前时间
	now := time.Now()
	p(now)

	//提供年月日等信息，构建一个time
	then := time.Date(2023, 10, 24, 19, 38, 58, 701212455, time.UTC)
	p(then)

	p(then.Year())
	p(then.Month())
	p(then.Day())
	p(then.Hour())
	p(then.Minute())
	p(then.Second())
	p(then.Nanosecond())
	p(then.Location())

	p(then.Weekday())

	//这些方法来比较两个时间，分别测试一下是否是之前，之后或者是同一时刻，精确到秒
	p(then.Before(now))
	p(then.After(now))
	p(then.Equal(now))

	//sub返回一个duration来表示两个时间点的间隔时间
	diff := now.Sub(then)
	p(diff)

	//计算不同单位下的时间长度值
	p(diff.Hours())
	p(diff.Minutes())
	p(diff.Seconds())
	p(diff.Nanoseconds())

	//使用add将时间后移一个时间间隔
	//或者使用一个'-'来将时间前移一个时间间隔
	p(then.Add(diff))
	p(then.Add(-diff))
}
